#ifndef HANDLEMPLAYER_H
#define HANDLEMPLAYER_H

#include <QObject>
#include <QProcess>
#include <QMainWindow>
#include <QWidget>
#include <QTimer>


class HandleMplayer : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString videoPlaying READ videoPlaying )
    //Q_PROPERTY(int length READ length)
    //Q_PROPERTY(int refreshPositionRate WRITE setRefreshPositionRate)

public:
    explicit HandleMplayer(QObject *parent = 0);
    ~HandleMplayer();
    Q_INVOKABLE void relativeSeek(int seconds);
    Q_INVOKABLE void pause();
    QString videoPlaying();
    Q_INVOKABLE void startVideo(QString videoId);
    //void setPlayerWindow(QMainWindow* w);

    //void setRefreshPositionRate(int seconds);
    //int length() const;
    //int position() const;

    QMainWindow *playerWin;
    QTimer *refreshTimer;

signals:
    void started(int length);
    void positionChanged(QString positionSeconds);
    void finished();
    void failedToStart();

    //void play();
    //void paused();


private:
    QProcess *innerProcess;
    int length;
    QString appsHome ;
    QString videoIdLoading;
    QString videoIdToLoad;
    void sendOrder(QString line);
    void startProcess();

private slots:
    void readyToRead();
    void readyToReadError();
    void refreshPosition();
    void processFinished(int exitCode, QProcess::ExitStatus exitStatus);

} ;



#endif // HANDLEMPLAYER_H
